<script lang="ts" setup>
import { onMounted, unref } from 'vue';
import { useRouter } from 'vue-router';

import { AuthenticationLogin } from '@vben/common-ui';

import { useAuthStore } from '#/store';

import { useFormSchema } from './data';

defineOptions({ name: 'Login' });

const router = useRouter();

const { formSchema, loadCaptcha, uuid } = useFormSchema();

onMounted(() => {
  loadCaptcha();
});

const authStore = useAuthStore();
const submitHandle = async (form: any) => {
  await authStore.authLogin({ ...form, userUid: unref(uuid) }, () => {
    router.push('/home');
  });
};
</script>

<template>
  <div>
    <AuthenticationLogin
      :form-schema="formSchema"
      :loading="authStore.loginLoading"
      :show-code-login="false"
      :show-qrcode-login="false"
      :show-third-party-login="false"
      @submit="submitHandle"
    />
  </div>
</template>
